<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>todo list</title>
  <script src="/vue.js"></script>
</head>
<body>
  <div id="root">
    <div>
      <input 
        type="text" 
        v-model="keywords"
        v-on:keyup.enter="handleKeyup"
      >
      <!-- 数据双向绑定 -->
      <!-- <span>{{keywords}}</span> -->
    </div>
    <ul>
      <li v-for="(task, index) in tasks">
        {{task}} - {{index}}
        <button v-on:click="handleClick(index)">remove</button>
      </li>
    </ul>
  </div>
  <script>
    var vm = new Vue({
      el: '#root',
      data: {
        keywords: '',
        tasks: [
          'task one',
          'task two',
          'task three'
        ] 
      },
      methods: {
        handleKeyup(e) {
          this.tasks.push(this.keywords)
          this.keywords = ''
        },
        handleClick(index) {
          // 操作数据
          // console.log(index)
          this.tasks.splice(index, 1)
        }
      },
    })
  </script>
</body>
</html>